function a(a, e, t) {
    return e in a ? Object.defineProperty(a, e, {
        value: t,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[e] = t, a;
}

require("../../utils/util.js");

var e = getApp();

Page({
    data: {
        toast1Hidden: !0,
        modalHidden: !0,
        modalHidden2: !0,
        notice_str: "",
        hiddenToast: !0,
        index: 0,
        nickName: e.globalData.nickName,
        avatarUrl: e.globalData.avatarUrl,
        showButton1: !1,
        showButton2: !1,
        dialog: {
            title: "绑定手机号",
            hidden: !1
        },
        phone: e.globalData.phone ? e.globalData.phone : wx.getStorageSync("phone"),
        codename: "获取验证码",
        getCode: "getCode",
        iscode: null,
        phoneModal: "",
        is_send: 0,
        is_phone: 0
    },
    onReady: function() {
        var a = this, t = wx.getStorageSync("nickName"), o = wx.getStorageSync("avatarUrl"), n = wx.getStorageSync("userId"), l = wx.getStorageSync("phone") ? wx.getStorageSync("phone") : e.globalData.phone;
        t && t.length > 0 && (e.globalData.nickName = t), o && o.length > 0 && (e.globalData.avatarUrl = o), 
        l && l.length > 0 && (e.globalData.phone = l, a.setData({
            phoneModal: !1,
            is_phone: 1
        })), l.length < 0 && a.setData({
            phoneModal: !1,
            is_phone: 0
        }), n && n.length > 0 && (e.globalData.userId = n);
    },
    getuserinfo: function(a) {
        var t = this;
        t.setData({
            nickName: a.detail.userInfo.nickName,
            avatarUrl: a.detail.userInfo.avatarUrl
        }), e.globalData.avatarUrl = t.data.avatarUrl, e.globalData.nickName = t.data.nickName, 
        t.userLogin();
    },
    userLogin: function() {
        var t = this;
        wx.login({
            success: function(o) {
                var n = e.globalData.urlBase + e.globalData.urlCode2openId;
                wx.request({
                    url: n,
                    data: {
                        code: o.code
                    },
                    method: "POST",
                    header: {
                        "content-type": "application/x-www-form-urlencoded"
                    },
                    success: function(o) {
                        var n = JSON.parse(o.data);
                        wx.setStorageSync("avatarUrl", t.data.avatarUrl), wx.setStorageSync("nickName", t.data.nickName), 
                        wx.setStorageSync("phone", t.data.phone), wx.setStorageSync("userId", n.openid), 
                        e.globalData.userId = n.openid;
                        
                        var l = e.globalData.urlBase + e.globalData.urlCheckUser;
                        wx.request({
                            url: l,
                            data: {
                                openId: e.globalData.userId,
                                headImg: e.globalData.avatarUrl,
                                nickName: e.globalData.nickName,
                                phone: e.globalData.phone
                            },
                            method: "POST",
                            header: {
                                "content-type": "application/x-www-form-urlencoded"
                            },
                            success: function(a) {
                                var e = JSON.parse(a.data);
                                0 != e.code && (wx.showToast({
                                    title: e.msg,
                                    icon: "none",
                                    duration: 2e3
                                }), wx.clearStorage());
                            }
                        }), wx.request({
                            url: e.globalData.baseUrl + e.globalData.urlCheckUser2,
                            data: {
                                openId: e.globalData.userId
                            },
                            method: "POST",
                            header: {
                                "content-type": "application/x-www-form-urlencoded"
                            },
                            success: function(o) {
                                var n = JSON.parse(o.data);
                                if (0 != n.code) {
                                    d = "dialog.hidden";
                                    t.setData(a({}, d, !1));
                                } else {
                                    var l;
                                    wx.setStorageSync("phone", n.msg), e.globalData.phone = n.msg;
                                    var d = "dialog.hidden";
                                    t.setData((l = {}, a(l, d, !0), a(l, "phone", n.msg), a(l, "is_phone", 1), l)), 
                                    1 == e.globalData.ctData.ctshare && 1 == e.globalData.ctData.actType && (console.log("ok"), 
                                    wx.navigateTo({
                                        url: "../collageDetails/collageDetails?id=" + e.globalData.ctData.activityId + "&type=1&orderid=" + e.globalData.ctData.orderId + "&ctshare=1"
                                    }), e.globalData.ctData = {});
                                }
                            }
                        });
                    }
                });
            }
        });
    },
    showbutton: function() {
        var a = this;
        a.setData({
            showButton1: !a.data.showButton1
        }), 1 == a.data.showButton2 && a.setData({
            showButton2: !a.data.showButton2
        });
    },
    listenerButton: function() {
        this.setData({
            hiddenToast: !this.data.hiddenToast
        });
    },
    toastHidden: function() {
        this.setData({
            hiddenToast: !0
        });
    },
    toast1Change: function(a) {
        this.setData({
            toast1Hidden: !0
        });
    },
    modalTap: function(a) {
        this.setData({
            modalHidden: !1
        });
    },
    confirm_one: function(a) {
        console.log(a), this.setData({
            modalHidden: !0,
            toast1Hidden: !1,
            notice_str: "提交成功"
        });
    },
    cancel_one: function(a) {
        console.log(a), this.setData({
            modalHidden: !0,
            toast1Hidden: !1,
            notice_str: "取消成功"
        });
    },
    modalTap2: function(a) {
        this.setData({
            modalHidden2: !1
        });
    },
    modalChange2: function(a) {
        this.setData({
            modalHidden2: !0
        });
    },
    bindPickerChange: function(a) {
        console.log("picker发送选择改变，携带值为", a.detail.value), this.setData({
            index: a.detail.value
        });
    },
    onLoad: function(t) {
        var o = this;
        if (e.globalData.userId && e.globalData.userId.length > 0) if (this.setData({
            nickName: e.globalData.nickName,
            avatarUrl: e.globalData.avatarUrl,
            showButton1: e.globalData.userId && e.globalData.userId.length > 0,
            showButton2: !e.globalData.userId || 0 == e.globalData.userId.length,
            userPhone: e.globalData.phone
        }), console.log(o.data.userPhone.length, o.data.userPhone), o.data.userPhone.length <= 0) {
            n = "dialog.hidden";
            o.setData(a({}, n, !1));
        } else {
            n = "dialog.hidden";
            o.setData(a({}, n, !0));
        } else {
            var n = "dialog.hidden";
            this.setData(a({
                showButton1: !1,
                showButton2: !0
            }, n, !0));
        }
    },
    formSubmit: function(a) {
        var t = this, o = a.detail.value;
        wx.request({
            url: e.globalData.urlBase + e.globalData.urlMessageAdd + e.globalData.urlAlias,
            method: "post",
            data: o,
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(a) {
                t.modalTap();
            }
        });
    },
    formReset: function() {
        this.modalTap2();
    },
    getPhoneValue: function(a) {
        this.setData({
            phone: a.detail.value
        });
    },
    getCodeValue: function(a) {
        this.setData({
            code: a.detail.value
        });
    },
    nedcode: function() {
        if (1 == this.data.is_send) return !1;
        this.data.phone;
        var a = this, t = /^(14[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$$/;
        if ("" == this.data.phone) return wx.showToast({
            title: "手机号不能为空",
            icon: "none",
            duration: 1e3
        }), !1;
        if (!t.test(this.data.phone)) return wx.showToast({
            title: "请输入正确的手机号",
            icon: "none",
            duration: 1e3
        }), !1;
        var o = 60;
        a.setData({
            disabled: !0,
            codename: o + "s"
        });
        var n = setInterval(function() {
            o--, a.setData({
                getCode: "getCode discode",
                codename: o + "s"
            }), o <= 0 && (clearInterval(n), a.setData({
                codename: "重新发送",
                disabled: !1,
                getCode: "getCode",
                is_send: 0
            }));
        }, 1e3);
        wx.request({
            url: e.globalData.baseUrl + "/m/getMobileMsg",
            data: {
                phone: a.data.phone
            },
            method: "POST",
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(e) {
                var t = JSON.parse(e.data);
                if (console.log(t), 1 == t.code) return wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 1e3
                }), clearInterval(n), a.setData({
                    codename: "获取验证码",
                    disabled: !1,
                    getCode: "getCode",
                    is_send: 0
                }), !1;
                a.setData({
                    is_send: 1
                });
            }
        }), a.setData({
            timer: n
        });
    },
    confirm1: function() {
        var e, t = this;
        clearInterval(t.data.timer), t.setData((e = {}, a(e, "dialog.hidden", !0), a(e, "codename", "获取验证码"), 
        a(e, "getCode", "getCode"), a(e, "code", ""), a(e, "phone", ""), a(e, "disabled", !1), 
        a(e, "is_send", 0), e));
    },
    confirm: function(t) {
        var o = /^(14[0-9]|13[0-9]|15[0-9]|17[0-9]|18[0-9])\d{8}$$/, n = this;
        return "" == n.data.phone ? (wx.showToast({
            title: "手机号不能为空",
            icon: "none",
            duration: 1e3
        }), !1) : o.test(n.data.phone) ? "" == n.data.code ? (wx.showToast({
            title: "验证码不能为空",
            icon: "none",
            duration: 1e3
        }), !1) : void wx.request({
            url: e.globalData.urlBase + "/checkMobileMsg",
            method: "POST",
            data: {
                code: n.data.code,
                phone: n.data.phone,
                userId: e.globalData.userId
            },
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(t) {
                var o = JSON.parse(t.data);
                if (0 != o.code) wx.showToast({
                    title: o.msg,
                    icon: "none",
                    duration: 2e3
                }); else {
                    var l;
                    e.globalData.phone = n.data.phone, wx.setStorageSync("phone", n.data.phone), n.userLogin();
                    clearInterval(n.data.timer), n.setData((l = {}, a(l, "dialog.hidden", !0), a(l, "code", ""), 
                    a(l, "phone", ""), a(l, "codename", "获取验证码"), a(l, "getCode", "getCode"), a(l, "disabled", !1), 
                    a(l, "is_phone", 1), l));
                }
            }
        }) : (wx.showToast({
            title: "请输入正确的手机号",
            icon: "none",
            duration: 1e3
        }), !1);
    },
    onShareAppMessage: function() {
        var a = getCurrentPages();
        a[a.length - 1];
        return {
            title: e.globalData.urlShareTile,
            path: "/pages/message/index",
            success: function(a) {},
            fail: function(a) {}
        };
    },
    phonebd: function(e) {
        this.setData(a({
            phoneModal: !0
        }, "dialog.hidden", !1));
    }
});